const showToast = (param) => {
	uni.showToast({
		title: param.title || '提示',
		icon: param.icon || 'success',
		image: param.image || null,
		mask: param.mask || false,
		duration: param.duration || 1500,
		position: param.position || null
	})
}

const success = (param) => {
	param = checkedToastParams(param)
	param.icon = 'success'
	showToast(param);
}

const error = (param) => {
	param = checkedToastParams(param)
	param.icon = 'error'
	showToast(param);
}

const none = (param) => {
	param = checkedToastParams(param)
	param.icon = 'none'
	showToast(param);
}

const exception = (param) => {
	param.icon = 'exception'
	showToast(param);
}

const checkedToastParams = (param) => {
	if (typeof param === 'string') {
		let message = param;
		param = {
			title: message
		};
	}
	return param;
}

const showLoading = (param) => {
	param = param || {}
	uni.showLoading({
		title: param.title || '加载中',
		mask: param.mask || false
	});
}

const hideLoading = () => {
	uni.hideLoading()
}

module.exports = {
	success,
	error,
	none,
	exception,
	showLoading,
	hideLoading
}